466B - Wonder Room - CodeForces Solution


brute force math *2000

Please click on ads to support us..

Python Code:

import sys
input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

def Wonder_Room():
    import math
    n,a,b = invr()

    min_area_reqd = 6*n 

    if min_area_reqd <= (a*b):
        print(a*b)
        print(str(a) + ' ' + str(b))
    
    else:
        max_room_size = int(math.sqrt(min_area_reqd)) + 1

        min_area = -1 
        corresponding_a = -1
        corresponding_b = -1

        if a < b: 
            room1_size_min = a 
            room2_size_min = b 
        else:
            room1_size_min = b 
            room2_size_min = a 

        for room1_size in range(room1_size_min,max_room_size):
            room2_size = math.ceil(min_area_reqd/room1_size)
            current_area = room1_size * room2_size

            if room2_size >= room2_size_min and min_area == -1:
                min_area = current_area

                if a<b:
                    corresponding_a = room1_size
                    corresponding_b = room2_size
                else:
                    corresponding_b = room1_size
                    corresponding_a = room2_size

            elif room2_size >= room2_size_min  and current_area < min_area:
                min_area = current_area

                if a < b:
                    corresponding_a = room1_size
                    corresponding_b = room2_size
                else:
                    corresponding_b = room1_size
                    corresponding_a = room2_size
        
        print(min_area)
        print(str(corresponding_a) + ' ' + str(corresponding_b))
    
    return

Wonder_Room()


Comments

Submit
0 Comments
More Questions

1711A - Perfect Permutation
1701B - Permutation
1692A - Marathon
1066A - Vova and Train
169B - Replacing Digits
171D - Broken checker
380C - Sereja and Brackets
1281B - Azamon Web Services
1702A - Round Down the Price
1681C - Double Sort
12A - Super Agent
1709A - Three Doors
1680C - Binary String
1684B - Z mod X = C
1003A - Polycarp's Pockets
1691B - Shoe Shuffling
1706A - Another String Minimization Problem
1695B - Circle Game
1702B - Polycarp Writes a String from Memory
1701A - Grass Field
489C - Given Length and Sum of Digits
886B - Vlad and Cafes
915A - Garden
356A - Knight Tournament
1330A - Dreamoon and Ranking Collection
1692B - All Distinct
1156C - Match Points
1675A - Food for Animals
1328C - Ternary XOR
1689A - Lex String